package com.toe.user.webapi.controller;


import com.toe.common.restful.JsonResult;
import com.toe.pojo.dto.user.UserRolePermissionAddDTO;
import com.toe.user.service.UserRolePermissionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 角色权限关联表 前端控制器
 * </p>
 *
 * @author 陶涛
 * @since 2022-07-19
 */
@RestController
@RequestMapping("/webapi/user-role-permission")
@Api(tags = "角色权限映射")
public class UserRolePermissionController {
    @Autowired
    private UserRolePermissionService userRolePermissionService;

    @ApiOperation("添加映射")
    @PostMapping("/insert")
    public JsonResult<Void> insert(@RequestBody UserRolePermissionAddDTO userRolePermissionAddDTO){
        userRolePermissionService.insert(userRolePermissionAddDTO);
        return JsonResult.ok();
    }

    @ApiOperation("删除映射")
    @PostMapping("/delete/{id}")
    public JsonResult<Void> delete(@PathVariable Long id){
        userRolePermissionService.delete(id);
        return JsonResult.ok();
    }

    @ApiOperation("删除指定映射")
    @PostMapping("/delete")
    public JsonResult<Void> delete(Long roleId,long permissionId){
        userRolePermissionService.delete(roleId,permissionId);
        return JsonResult.ok();
    }

    @ApiOperation("查询指定映射是否存在")
    @PostMapping("/select")
    public JsonResult<Boolean> select(Long roleId,long permissionId){
        Boolean aBoolean = userRolePermissionService.selectOne(roleId, permissionId);
        return JsonResult.ok(aBoolean);
    }
}

